package com.dineroquegastar.urule.interceptor;

import com.bstek.urule.console.AdminEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class LoginInterceptor extends HandlerInterceptorAdapter{

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        AdminEntity adminEntity =(AdminEntity)request.getSession().getAttribute("admin");
        if(adminEntity!=null){
            return true;
        }
        response.sendRedirect("/");
        return false;
    }
}
